package com.iot.ic.service;


import com.iot.ic.common.CustomException;
import com.iot.ic.dao.IllegalResultMapper;
import com.iot.ic.model.IllegalResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by xiuge on 2017/2/20.
 */
@Service
public class IllegalResultServiceImpl implements IllegalResultService {

	@Autowired
	private IllegalResultMapper illegalResultMapper;

	@Autowired
	private ScenesResultService scenesResultService;

	@Override
	public List<Map<String, Object>> getIllegalResultList(int count,int teamId, String startTime, String endTime) {
		List<Map<String,Object>> list=illegalResultMapper.selectIllegalResultList(count, teamId, startTime, endTime);
		return list;
	}

	@Override
	public int addIllegalResult(IllegalResult illegalResult) {
		int result = illegalResultMapper.insert(illegalResult);
		return result;
	}

	@Override
	public List<IllegalResult> listIllegalResultByScenes(int scenesResultId) {
		List<IllegalResult> result = illegalResultMapper.selectIllegalResultListByScenes(scenesResultId);
		return result;
	}

	@Override
	public int deleteIllegalResult(int illegalResultId) {
		int result = illegalResultMapper.deleteIllegalResult(illegalResultId);
		return result;
	}

	/**
	 * @param illegalResult
	 * @return
	 */
	@Override
	public int modIllegalResult(IllegalResult illegalResult) {
		int result=illegalResultMapper.updateByPrimaryKeySelective(illegalResult);
		if (result==1){
			IllegalResult illegalResult1=illegalResultMapper.selectByPrimaryKey(illegalResult.getIllegalResultId());
			int result1=scenesResultService.updateScenceScore(illegalResult1.getScenesResultId());
			return result1;
		}else {
			throw new CustomException("更新违规记录失败");
		}
	}

	@Override
	public Map<String, Object> getStadiumScenesByIllegal(int illegalResultId) {
		Map<String,Object> resultMap = illegalResultMapper.selectStadiumScenesByIllegal(illegalResultId);
		return resultMap;
	}

	@Override
	public int deleteIllegalResultByScenesResultId(int scenesResultId) {
		int delFlag = illegalResultMapper.deleteIllegalResultByScenesResult(scenesResultId);
		return delFlag;
	}

	@Override
	public int insertIllegalResultBatch(List<IllegalResult> illegalResultList) {
		int result = illegalResultMapper.addIllegalResultBatch(illegalResultList);
		return result;
	}
}
